package com.iyao_app.mvp.password;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.iyao_app.R;
import com.mingle.widget.ShapeLoadingDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/11/14.
 */

public class ForgetActivity extends AppCompatActivity {

    @BindView(R.id.rl_root)
    RelativeLayout mRlRoot;
    @BindView(R.id.fl_content)
    FrameLayout mFlContent;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    private Bitmap bm;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏
        setContentView(R.layout.activity_forget);
        ButterKnife.bind(this);
        bm = BitmapFactory.decodeResource(this.getResources(), R.mipmap.bg_ditu_denglu);
        BitmapDrawable bd = new BitmapDrawable(this.getResources(), bm);
        mRlRoot.setBackgroundDrawable(bd);
        init();
    }

    private void init() {

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fl_content, new ForgetPasswordFragment(), ForgetPasswordFragment.class.getSimpleName())
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .commit();
    }

    public void changeFragment(Bundle bundle) {
        ForgetNextFragment fragment = new ForgetNextFragment();
        fragment.setArguments(bundle);
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fl_content, fragment, ForgetNextFragment.class.getSimpleName())
                .addToBackStack(ForgetNextFragment.class.getSimpleName())
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .commit();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        BitmapDrawable bd = (BitmapDrawable) mRlRoot.getBackground();
        bm=null;
        mRlRoot.setBackgroundDrawable(null);
        bd.setCallback(null);
        bd.getBitmap().recycle();
    }

    ShapeLoadingDialog shapeLoadingDialog;

    public void showDialog() {
        shapeLoadingDialog = new ShapeLoadingDialog.Builder(this)
                .loadText("加载中...")
                .cancelable(false)
                .build();
        shapeLoadingDialog.show();
    }

    public void closeDialog() {
        if (shapeLoadingDialog != null)
            shapeLoadingDialog.dismiss();
        shapeLoadingDialog = null;
    }
    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
            //从回退栈里弹出最新加入的Fragment
            getSupportFragmentManager().popBackStackImmediate();
        } else {
            finish();
        }

    }
}
